package tds.model9.version1;

/**
 * 
 * @Company 杭州先锋电子技术股份有限公司
 * @ClassName Calculation
 * @Description TODO(计算类)
 * @author tds
 * @Date 2019年1月3日 下午1:51:17
 * @version 1.0.0
 */
public class Calculation {
	public static double calculate(double param1, double param2, String operator){
		Operate operate = Operate.valueOperationOf(operator);
		if(operate == null){
			throw new RuntimeException("操作符不存在");
		}

		Calculate calculate ;
		switch (operate) {
			case ADD:
				calculate = new AddFactory().getCalculate();
				break;
			case SUB:
				calculate = new SubFactory().getCalculate();
				break;
			case MUL:
				calculate = new MulFactory().getCalculate();
				break;
			case DIV:
				calculate = new DivFactory().getCalculate();
				break;

			default:
				throw new RuntimeException("未知的操作符");
		}
		calculate.setParam1(param1);
		calculate.setParam2(param2);
		return calculate.calulate();
	}
}
